package com.ruoyi.service.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.service.domain.ServiceNotice;
import com.ruoyi.service.service.IServiceNoticeService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 通知公告Controller
 * 
 * @author yepanpan
 * @date 2025-05-06
 */
@RestController
@RequestMapping("/service/notice")
public class ServiceNoticeController extends BaseController
{
    @Autowired
    private IServiceNoticeService serviceNoticeService;

    /**
     * 查询通知公告列表
     */
    @PreAuthorize("@ss.hasPermi('service:notice:list')")
    @GetMapping("/list")
    public TableDataInfo list(ServiceNotice serviceNotice)
    {
        startPage();
        List<ServiceNotice> list = serviceNoticeService.selectServiceNoticeList(serviceNotice);
        return getDataTable(list);
    }

    /**
     * 导出通知公告列表
     */
    @PreAuthorize("@ss.hasPermi('service:notice:export')")
    @Log(title = "通知公告", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ServiceNotice serviceNotice)
    {
        List<ServiceNotice> list = serviceNoticeService.selectServiceNoticeList(serviceNotice);
        ExcelUtil<ServiceNotice> util = new ExcelUtil<ServiceNotice>(ServiceNotice.class);
        util.exportExcel(response, list, "通知公告数据");
    }


    /**
     * 获取通知公告详细信息
     */
    @PreAuthorize("@ss.hasPermi('service:notice:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(serviceNoticeService.selectServiceNoticeById(id));
    }

    /**
     * 新增通知公告
     */
    @PreAuthorize("@ss.hasPermi('service:notice:add')")
    @Log(title = "通知公告", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Validated @RequestBody ServiceNotice serviceNotice)
    {
                serviceNotice.setCreateBy(getUsername());
        return toAjax(serviceNoticeService.insertServiceNotice(serviceNotice));
    }

    /**
     * 修改通知公告
     */
    @PreAuthorize("@ss.hasPermi('service:notice:edit')")
    @Log(title = "通知公告", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@Validated @RequestBody ServiceNotice serviceNotice)
    {
                serviceNotice.setUpdateBy(getUsername());
        return toAjax(serviceNoticeService.updateServiceNotice(serviceNotice));
    }

    /**
     * 删除通知公告
     */
    @PreAuthorize("@ss.hasPermi('service:notice:remove')")
    @Log(title = "通知公告", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(serviceNoticeService.deleteServiceNoticeByIds(ids));
    }
}
